package com.app.shop.adapters;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.app.shop.R;
import com.app.shop.beans.DTBean;
import com.app.library.utils.GlideUtils;
import com.app.library.utils.UserManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;


public class DTListAdapter extends BaseQuickAdapter<DTBean, DTListAdapter.ViewHolder> {


    public DTListAdapter(int layout, @Nullable List<DTBean> data) {
        super(layout, data);
    }


    @Override
    protected void convert(ViewHolder holder, DTBean bean) {

        GlideUtils.getInstance().loadImage(mContext, bean.pic, holder.imgv_pic);
        holder.tv_name.setText(bean.title);
        holder.tv_user.setText("发布者：" + bean.user_name);
        holder.tv_content.setText(bean.content);
        holder.tv_del.setText("删除");
        holder.tv_del.setVisibility(bean.user_id.equals(UserManager.getUserId(mContext)) ? View.VISIBLE : View.GONE);
        holder.addOnClickListener(R.id.tv_del_item);
    }


    public class ViewHolder extends BaseViewHolder {
        ImageView imgv_pic;
        TextView tv_name;
        TextView tv_user;
        TextView tv_content;
        TextView tv_del;


        public ViewHolder(View view) {
            super(view);
            imgv_pic = view.findViewById(R.id.imgv_list);
            tv_name = view.findViewById(R.id.tv_list_item);
            tv_user = view.findViewById(R.id.tv_list_user);
            tv_content = view.findViewById(R.id.tv_list_content);
            tv_del = view.findViewById(R.id.tv_del_item);
        }
    }
}
